export default {
  setUsers (state, users) {
    state.users = users
  },
  toggleLoading (state, loading) {
    state.loading = loading
  },
  setSearch (state, payload) {
    // payload是一个对象，可以是 {page: 2} {total: 999}
    /* 
      const obj = {a:1, b: 2, c: 3}
      const obj2 = {c: 2}
      const o = {...obj, ...obj2}
    
    */
    state.search = {
      ...state.search,
      ...payload
    }
  },
  removeUser (state, index) {
    state.users.splice(index, 1)
  },
  setIds (state, ids) {
    state.ids = ids
  },
  removeUsers (state) {
    const ids = state.ids.split(',')
    state.users = state.users.filter(user => !ids.includes(user.id))
  }
}